<?php
/*
  $Id: customer_testimonials.php,v 1.3 2003/12/08 Exp $

*/

  // Ensure a valid runtime environment or die
  if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );

  // Check if osCommerce environment is already loaded
  if (defined( '_OSCOMMERCE_LOADED' )) {
    if (!DB_SHARED) {
      // Reconnect to osCommerce Database
      tep_db_connect() or die('Unable to connect to database server!');
    }
    // Load osCommerce Globals for Boxes
    global $category_links, $languages_id, $catID, $catID_array, $current_category_id;
    global $request_type, $lng, $cart, $currencies, $language, $navigation, $breadcrumb;
  } else {
    // Load osCommerce Environment for the First Time
    require('components/'.$option.'/includes/application_top.php');
    
  }

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_CUSTOMER_TESTIMONIALS);
$breadcrumb->add(NAVBAR_TITLE, tep_href_link('customer_testimonials.php', '', 'NONSSL'));

  $location = ' &raquo; <a href="' . tep_href_link(FILENAME_CUSTOMER_TESTIMONIALS, '', 'NONSSL') . '" class="headerNavigation">' . NAVBAR_TITLE . '</a>';
 require(DIR_WS_INCLUDES . 'header.php');
             if ($testimonial_id != '') {
                $full_testimonial = tep_db_query("select * FROM " . TABLE_CUSTOMER_TESTIMONIALS . " WHERE testimonials_id = $testimonial_id");
            }
            else {
                $full_testimonial = tep_db_query("select * FROM " . TABLE_CUSTOMER_TESTIMONIALS . " WHERE status = '1'");
            }
            while ($testimonials = tep_db_fetch_array($full_testimonial)) {
                $testimonial_array[] = array('id' => $testimonials['testimonials_id'],
                                             'author' => $testimonials['testimonials_name'],
                                             'testimonial' => $testimonials['testimonials_html_text'],
                                             'word_count' => tep_word_count($testimonials['testimonials_html_text'], '3'),
                                             'url' => $testimonials['testimonials_url'],
                                             'url_title' => $testimonials['testimonials_url_title']);
                }

if ($_REQUEST['action']) {
    switch ($_REQUEST['action']) {      
      case 'insert':      
        $testimonials_id = $_POST['testimonials_id'];
        $testimonials_title = $_POST['testimonials_title'];
        $testimonials_url = $_POST['testimonials_url'];
        $testimonials_url_title = $_POST['testimonials_url_title'];
        $testimonials_name = $_POST['testimonials_name'];
        $html_text = $_POST['html_text'];
        $testimonials_error = false;
        $messageStack = ERROR_HEADER;
        if (empty($testimonials_title)) {
          $messageStack .= '['.ERROR_TESTIMONIALS_TITLE_REQUIRED.']';
          $testimonials_error = true;
        }
        if (empty($testimonials_name)) {
          $messageStack .= '['.ERROR_TESTIMONIALS_NAME_REQUIRED.']';
          $testimonials_error = true;
        }
        if (empty($html_text)) {
          $messageStack.= '['.ERROR_TESTIMONIALS_DESCRIPTION_REQUIRED.']';
          $testimonials_error = true;
        }

        if (!$testimonials_error) {
          $sql_data_array = array('testimonials_title' => $testimonials_title,
                                  'testimonials_url' => $testimonials_url,
                                  'testimonials_url_title' => $testimonials_url_title,
                                  'testimonials_name' => $testimonials_name,
                                  'testimonials_html_text' => $html_text);
         if ($_REQUEST['action'] == 'insert') {
           $insert_sql_data = array('date_added' => 'now()',
                                     'status' => '0');
            $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
            tep_db_perform(TABLE_CUSTOMER_TESTIMONIALS, $sql_data_array);
            $testimonials_id = tep_db_insert_id();            
          }   

          $errmsg = TEXT_TESTIMONIALS_SUCCESSFUL;
          $testimonials_id = '';
           $testimonials_title = '';
           $testimonials_url = '';
           $testimonials_url_title = '';
           $testimonials_name = ''; 
           $html_text = '';    
        } else {          
           $errmsg = $messageStack;
           $testimonials_id = tep_db_prepare_input($_POST['testimonials_id']);
           $testimonials_title = tep_db_prepare_input($_POST['testimonials_title']);
           $testimonials_url = tep_db_prepare_input($_POST['testimonials_url']);
           $testimonials_url_title = tep_db_prepare_input($_POST['testimonials_url_title']);
           $testimonials_name = tep_db_prepare_input($_POST['testimonials_name']);
           $html_text = tep_db_prepare_input($_POST['html_text']);
        }
        break;     
    }
  }
require(WS_TEMPLATES. E_TEMPLATE_FOLDER . '/'.$osMod.'.html');
require(DIR_WS_INCLUDES . 'footer.php'); 
require(DIR_WS_INCLUDES . 'application_bottom.php');

  // reset the Mambo Database connection (stomped by osCommerce Connection)
  if (!DB_SHARED) {
    global $database, $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix;
    $database = new database( $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix );
  }
 ?>